package demo1125;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

/**
 * 2019/11/25
 * Administrator
 * shiroDemo1125
 * 面向对象面向君  不负代码不负卿
 */
public class Demo2 {

    public static void main(String[] args) {
        //认证测试-测试假数据
        //1.创建安全管理器对象工厂
        Factory<SecurityManager> iniSecurityManagerFactory =
                        new IniSecurityManagerFactory("classpath:myreala.ini");
        //2.安全管理器
        SecurityManager instance = iniSecurityManagerFactory.getInstance();
        //3.使框架管理该对象
        SecurityUtils.setSecurityManager(instance);
        //4。创建主体Subject对象
        Subject subject =SecurityUtils.getSubject();
        //5.指定被测试的用户名和密码
        UsernamePasswordToken token = new UsernamePasswordToken("admin","123");
        //6.提交用户名和密码.login(认证信息)
        subject.login(token);
        //7.得到认证结果,认证通过返回true,不通过报错
        System.out.println("认证结果A:"+subject.isAuthenticated());
        //8.当用户退出时，认证结果返回false
        subject.logout();
        System.out.println("认证结果B:"+subject.isAuthenticated());

    }
}
